function jQuery(selector){ //selector 可能是#id

    //根据id获取元素
    if (typeof selector == "string") {
        if (selector.charAt(0) == "#"){
            domObj = document.getElementById(selector.substring(1))//"btn"
            return new jQuery();
        }
    }

    //页面加载完毕后，注册回调函数
    if (typeof selector == "function"){
        window.onload = selector
    }

    //html()方法代替domObj。innerHTML=""
    this.html = function (htmlStr){
        domObj.innerHTML = htmlStr
    }

    this.appe = function (optionHtml){
        domObj.append(optionHtml)
    }

    //定义click代替 domObj.onclick = function () {}
    this.click = function (fun) {
        domObj.onclick = fun
    }

    this.val = function (v) {
        if (v == undefined)
        {
            return domObj.value
        }else {
            domObj.value = v
        }
    }

    jQuery.ajax = function (jsonArgs){
        var xhr =new XMLHttpRequest();
        //2.注册回调函数
        xhr.onreadystatechange = function (){
            if (this.readyState == 4) {
                if(this.status=200)
                {
                    var jsonObj = JSON.parse(this.responseText)
                    jsonArgs.success(jsonObj)

                }else {
                    alert(this.status)
                }
            }
        }

        if (jsonArgs.type.toUpperCase() == "POST") {
            //3.开启通道
            xhr.open("POST",jsonArgs.url,jsonArgs.async)
            //4.发送请求
            xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
            xhr.send(jsonArgs.data)
        }

        if (jsonArgs.type.toUpperCase() == "GET") {
            xhr.open("GET",jsonArgs.url + "?" + jsonArgs.data, jsonArgs.async)
            xhr.send()
        }

    }
}

$=jQuery

new jQuery()